// example_text_file_writer.cpp : Defines the entry point for the console application.
//
/*

#include "stdafx.h"
#include <Inklude/ikCNetClientFactory.h>
#include <Windows.h>

using namespace Inklude;

int _tmain(int argc, _TCHAR* argv[])
{   
    std::shared_ptr<ikINetClient> pClient = ikCNetClientFactory::CreateClient(Inklude::NET_OPTION::TCP_SYNC);
    pClient->Initialize(9939);
    pClient->SetDestinationAddress("127.0.0.1", 9999);


    int count = 0;
    char *buffer = new char[6000];

    while (true)
    {
        count++;
        sprintf(buffer, "this is #%d\n", count);
        if(6000 == pClient->Send(buffer, 6000))
        {
            printf("%d successed\n", count);
        }
        //Sleep(100);
    }

	return 0;
}

*/



// Async Routine
#include "stdafx.h"
#include <Inklude/ikCNetClientFactory.h>
#include <Windows.h>
#include <time.h>

using namespace Inklude;
int _tmain(int argc, _TCHAR* argv[])
{   
    auto client = ikCNetClientFactory::CreateClient(Inklude::NET_OPTION::TCP_ASYNC);
    client->SetDestinationAddress("127.0.0.1", 9999);
    char *buffer = new char[60000];

    srand(time(NULL));

    ikINetClient::AsyncHandler handler;
    handler.reset(new std::function<void(size_t)>([&](size_t recvSize)
    {
        int count = rand() % 23432;
        sprintf(buffer, "this is #%d\n", count);
        
        printf(buffer);
        client->Send(buffer, 6000, handler);
    }
    ));
    
    client->Send(buffer, 6000, handler);

    while(true)
    {
        Sleep(1000);
        printf("CLIENT main thread\n");
    }
	return 0;
}
